/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.view.crud.tableModels;

import java.util.List;
import systole.domain.report.template.Comment;
import systole.view.messages.EntityDescriptions;

/**
 *
 * @author jmj
 */
public class CommentTableModel extends SystoleTableModel<Comment> {

    private String[] columnNames = {"Nombre", EntityDescriptions.COMMENT};
    private static final int NAME_INDEX = 0;
    private static final int DESCRIPTION_INDEX = 1;

    /**
     * @param comments
     */
    public CommentTableModel(List<Comment> comments) {
        super(comments);
    }

    public int getColumnCount() {
        return this.columnNames.length;
    }

    public String getColumnName(int columnIndex) {
        return this.columnNames[columnIndex];
    }

    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case NAME_INDEX:
                return String.class;
            case DESCRIPTION_INDEX:
                return String.class;
        }
        return null;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case NAME_INDEX:
                return this.entities.get(rowIndex).getName();
            case DESCRIPTION_INDEX:
                return this.entities.get(rowIndex).getText();
        }
        return null;
    }

    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case NAME_INDEX:
                this.entities.get(rowIndex).setName((String) aValue);
                break;
            case DESCRIPTION_INDEX:
                this.entities.get(rowIndex).setText((String) aValue);
                break;
        }
    }
}
